/*******************************************************************************
 * Copyright (c) 2012 AwOiSoAk.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 * 
 * Contributors:
 *     $AwOiSoAk - initial API and implementation
 ******************************************************************************/
package com.awoisoak.dundeeguide;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;

public class MyGallery extends Activity {
	
	private static Integer[] picturesDundeeLaw = {
            R.drawable.dundeelaw,
            R.drawable.dundeelaw2,
            R.drawable.dundeelaw3,
            R.drawable.dundeelaw4,
            R.drawable.dundeelaw5,
            R.drawable.dundeelaw6,
    };
	private Integer[] picturesMcManus = {
            R.drawable.mcmanus,
            R.drawable.mcmanus2,
            R.drawable.mcmanus3,
            R.drawable.mcmanus4,
            R.drawable.mcmanus5,
    };
	private Integer[] picturesDiscoveryPoint = {
            R.drawable.discoverypoint,
            R.drawable.discoverypoint2,
            R.drawable.discoverypoint3,
            R.drawable.discoverypoint4,
            R.drawable.discoverypoint5,
            R.drawable.discoverypoint6,
    };
	private Integer[] picturesHighStreet = {
            R.drawable.highstreet,
            R.drawable.highstreet2,
            R.drawable.highstreet3,
            R.drawable.highstreet4,
            R.drawable.highstreet5,
            R.drawable.highstreet6,

    };
	private Integer[] picturesBroughtyFerry = {
            R.drawable.broughtyferry,
            R.drawable.broughtyferry2,
            R.drawable.broughtyferry3,
            
    };
	
    String places;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gallery);

	    Bundle extras = getIntent().getExtras();
	    if(extras!=null){
	    	places = extras.getString("tag_place");
	    	}
	    
	    final ImageView imageViewGallery = (ImageView)findViewById(R.id.imageViewGallery);
	    Gallery gallery = (Gallery) findViewById(R.id.gallery);
	    
	    if (places.equals("Dundee Law")){
	    	gallery.setAdapter(new ImageAdapterDundeeLaw(this));
	    	imageViewGallery.setImageResource(picturesDundeeLaw[0]);}

	    else if (places.equals("McManus Galleries")){
	    	gallery.setAdapter(new ImageAdapterMcManus(this));
		    imageViewGallery.setImageResource(picturesMcManus[0]);}
	    
	    else if (places.equals("Discovery Point")){
	    	gallery.setAdapter(new ImageAdapterDiscoveryPoint(this));
		    imageViewGallery.setImageResource(picturesDiscoveryPoint[0]);}
	    
	    else if (places.equals("High Street")){
	    	gallery.setAdapter(new ImageAdapterHighStreet(this));
		    imageViewGallery.setImageResource(picturesHighStreet[0]);}
	    
	    else if (places.equals("Broughty Ferry Castle")){
	    	gallery.setAdapter(new ImageAdapterBroughtyFerry(this));
		    imageViewGallery.setImageResource(picturesBroughtyFerry[0]);}
	    

	    gallery.setOnItemSelectedListener(new OnItemSelectedListener(){
	    	public void onItemSelected(AdapterView<?> parent, View v, int position,long id) {
	            	
	            if (places.equals("Dundee Law")){
		            imageViewGallery.setImageResource(picturesDundeeLaw[position]);}
	            else if (places.equals("McManus Galleries")){
		            imageViewGallery.setImageResource(picturesMcManus[position]);}
	            else if (places.equals("Discovery Point")){
		            imageViewGallery.setImageResource(picturesDiscoveryPoint[position]);}
	            else if (places.equals("High Street")){
		            imageViewGallery.setImageResource(picturesHighStreet[position]);}
	            else if (places.equals("Broughty Ferry Castle")){
		            imageViewGallery.setImageResource(picturesBroughtyFerry[position]);}
	            	
			}

	    	
	    	
			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
	            Toast.makeText(MyGallery.this, "" + "nada seleccionado" , Toast.LENGTH_SHORT).show();
				
			}
	    });
	}
	    
	    

	
	
	//////////////////////////////////////////////////////////
	//Below the ImageAdapters for the different attractions //
	//////////////////////////////////////////////////////////

	

public class ImageAdapterDundeeLaw extends BaseAdapter {
	    int galleryBackground;
	    private Context context;
	    public ImageAdapterDundeeLaw(Context c) {
	        context = c;	          
	        TypedArray a = obtainStyledAttributes(R.styleable.GalleryTheme); 	       
	        galleryBackground =a.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
	        a.recycle(); 
		 
	    }
	    
		@Override
		public int getCount() {
			return picturesDundeeLaw.length;
		}
		
		
		@Override
		public Object getItem(int position) {
			return position;
		}
		@Override
		public long getItemId(int position) {
			return position;
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			ImageView imgView = new ImageView(context);
	        imgView.setImageResource(picturesDundeeLaw[position]);
	        imgView.setLayoutParams(new Gallery.LayoutParams(150, 100));
	        imgView.setScaleType(ImageView.ScaleType.FIT_XY);
	        imgView.setBackgroundResource(galleryBackground);
	        return imgView;
		}
	}

public class ImageAdapterMcManus extends BaseAdapter {
    int galleryBackground;
    private Context context;
    public ImageAdapterMcManus(Context c) {
        context = c;	          
        TypedArray a = obtainStyledAttributes(R.styleable.GalleryTheme); 	       
        galleryBackground =a.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
        a.recycle(); 
	 
    }
    
	@Override
	public int getCount() {
		return picturesMcManus.length;
	}
	 
	
	@Override
	public Object getItem(int position) {
		return position;
	}
	@Override
	public long getItemId(int position) {
		return position;
	}


	
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imgView = new ImageView(context);
        imgView.setImageResource(picturesMcManus[position]);
        imgView.setLayoutParams(new Gallery.LayoutParams(150, 100));
        imgView.setScaleType(ImageView.ScaleType.FIT_XY);
        imgView.setBackgroundResource(galleryBackground);
        return imgView;
	}
}//BaseAdapter

public class ImageAdapterDiscoveryPoint extends BaseAdapter {
    int galleryBackground;
    private Context context;
    public ImageAdapterDiscoveryPoint(Context c) {
        context = c;	          
        TypedArray a = obtainStyledAttributes(R.styleable.GalleryTheme); 	       
        galleryBackground =a.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
        a.recycle(); 
	 
    }
    
	@Override
	public int getCount() {
		return picturesDiscoveryPoint.length; 
	}
	
	
	@Override
	public Object getItem(int position) {
		return position;
	}
	@Override
	public long getItemId(int position) {
		return position;
	}


	
	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imgView = new ImageView(context);
        imgView.setImageResource(picturesDiscoveryPoint[position]);
        imgView.setLayoutParams(new Gallery.LayoutParams(150, 100));
        imgView.setScaleType(ImageView.ScaleType.FIT_XY);
        imgView.setBackgroundResource(galleryBackground);
        return imgView;
	}
}//BaseAdapter

public class ImageAdapterHighStreet extends BaseAdapter {
    int galleryBackground;
    private Context context;
    public ImageAdapterHighStreet(Context c) {
        context = c;	          
        TypedArray a = obtainStyledAttributes(R.styleable.GalleryTheme); 	       
        galleryBackground =a.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
        a.recycle(); 
	 
    }
    
	@Override
	public int getCount() {
		return picturesHighStreet.length;
	}
	
	
	@Override
	public Object getItem(int position) {
		return position;
	}
	@Override
	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imgView = new ImageView(context);
        imgView.setImageResource(picturesHighStreet[position]);
        imgView.setLayoutParams(new Gallery.LayoutParams(150, 100));
        imgView.setScaleType(ImageView.ScaleType.FIT_XY);
        imgView.setBackgroundResource(galleryBackground);
        return imgView;
	}
}

public class ImageAdapterBroughtyFerry extends BaseAdapter {
    int galleryBackground;
    private Context context;
    public ImageAdapterBroughtyFerry(Context c) {
        context = c;	          
        TypedArray a = obtainStyledAttributes(R.styleable.GalleryTheme); 	       
        galleryBackground =a.getResourceId(R.styleable.GalleryTheme_android_galleryItemBackground, 0);
        a.recycle(); 
	 
    }
    
	@Override
	public int getCount() {
		return picturesBroughtyFerry.length;
	}
	
	@Override
	public Object getItem(int position) {
		return position;
	}
	@Override
	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		ImageView imgView = new ImageView(context);
        imgView.setImageResource(picturesBroughtyFerry[position]);
        imgView.setLayoutParams(new Gallery.LayoutParams(150, 100));
        imgView.setScaleType(ImageView.ScaleType.FIT_XY);
        imgView.setBackgroundResource(galleryBackground);
        return imgView;
	}
}





}
